import ArrayUtil from '@/ArrayUtil';
import BaseUtil from '@/BaseUtil';
import SelectUtil from '@/SelectUtil';
import MathCommon from 'code/Core/Common/MathCommon';
import SLKCommon from 'code/Core/Common/SLKCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import VestCommon from 'code/Core/Common/VestCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 奔雷拳
 **/
export default class WS_ThunderFirst extends AbilityBase {
    static instance: WS_ThunderFirst;
    constructor(id: string = 'Ablq') {
        super(id);
        WS_ThunderFirst.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {}
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        DestroyEffect(AddSpecialEffectTarget('Abilities\\Weapons\\Bolt\\BoltImpact.mdl', source, 'origin'));
        let f = GetUnitFacing(source);
        let es = SelectUtil.getEnemyUnitsInLine(source, GetUnitX(source), GetUnitY(source), 200, f, 150);
        if (es.length == 0) return;
        let lv = this.getAbilityLevel(source);
        let dmg = UnitCommon.取攻击(source) * (0.7 + 0.4 * lv) + 25 * lv;

        let file = SLKCommon.getUnitModel(source);
        let v = VestCommon.getNoneModelVest(GetUnitX(source), GetUnitY(source), GetUnitFacing(source));
        DzSetUnitModel(v, file);
        SetUnitVertexColor(v, 255, 255, 255, 180);
        ShowUnitHide(source);
        let count = MathCommon.getAbilityEffectCount(4, source, this.id);
        BaseUtil.onTimer(0.1, (c) => {
            let tar = ArrayUtil.randomElement(es);
            DamageSystemInstance.applyAttackDamage(tar, source, dmg, this.id);
            DestroyEffect(AddSpecialEffectTarget('Abilities\\Weapons\\Bolt\\BoltImpact.mdl', tar, 'origin'));
            if (c == count - 1) {
                DzSetUnitModel(v, '');
                SetUnitVertexColor(v, 255, 255, 255, 255);
                VestCommon.returnVest(v);
                ShowUnitShow(source);
                SelectUnit(source, true);
            }
            return c < count - 1;
        });
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
